/**
 * 权限控制Hook
 */

import type { User } from '../utils/permission';

import { computed } from 'vue';

import {
  canCreateProposal,
  canEditMember,
  canMultiSign,
  getVoteWeight,
} from '../utils/permission';

export function usePermission() {
  // Mock当前用户（实际应从Pinia Store获取）
  const currentUser = computed<User>(() => ({
    id: 'zhu-4-1',
    role: 'emperor',
    kingdomId: 'central',
  }));

  const voteWeight = computed(() => getVoteWeight(currentUser.value));

  const isEmperor = computed(() => currentUser.value.role === 'emperor');

  const canPropose = computed(() => canCreateProposal(currentUser.value));

  const canSign = computed(() => canMultiSign(currentUser.value));

  return {
    currentUser,
    voteWeight,
    isEmperor,
    canPropose,
    canSign,
    canEditMember,
  };
}
